<?php
/**
 * Created by Jasmine.
 * Date: 2016/8/1
 * description:
 * Address: 浙江宣逸网络科技有限公司
 */

namespace Wap\Controller;


use Common\Model\PointMallModel;
use Common\Model\SignLuckyModel;
use Common\Model\UserModel;
use Common\Model\UtilsModel;
use Wap\BaseController;

class SignLuckyController extends BaseController{

    //签到大转盘
    public function lucky(){
        UtilsModel::checkLogin();
        $uid = session('uid')+0;
        if(!$uid){
            $luckyTimes = 0;
        } else{
            $data = UserModel::getSignTimes($uid);
            $luckyTimes = $data['luckyTimes'];
        }
        $this->smarty->assign('luckyTimes',$luckyTimes);
        $this->smarty->assign('uid',$uid);

        //取底图及抽奖规则
        $info = SignLuckyModel::getBasePicAndRegulations();
        $this->smarty->assign('info',$info);

        //是否当日首次签到
        signAssignWap($uid,$this->smarty);

        $this->smarty->assign('title','幸运大转盘');
        $this->smarty->display('SignLucky/lucky.html');
    }

    //奖品说明
    public function prizeIntroduce(){
        $type = I('get.type',2,'int');
        $set = SignLuckyModel::getLuckyPrizeNote($type);
        $this->smarty->assign('data',$set);

        //取底图
        $baseImg = SignLuckyModel::getPrizeBaseImg($type);
        $this->smarty->assign('baseImg',$baseImg);

        $uid = session("uid")+0;
        //是否当日首次签到
        signAssignWap($uid,$this->smarty);

        $this->smarty->assign('title',"奖品说明");
        $this->smarty->display("SignLucky/prizeIntro.html");
    }

    //取得大转盘抽奖结果
    public function getLuckyPrize(){
        UtilsModel::checkLogin();
        $uid = session('uid')+0;
        $type = I('get.type',SignLuckyModel::PRIZE_TYPE_SIGN_LUCKY,'int');
        $this->ajaxReturn(SignLuckyModel::getLuckyResult($uid,$type));
    }

    //计算再签到几天可获得抽奖机会
    public function countDays(){
        UtilsModel::checkLogin();
        $uid = session('uid')+0;
        $day = SignLuckyModel::getCountDays($uid);
        if($day<=0){
            $return=array('status'=>1,'msg'=>"亲，抽奖次数已用完");
        } else{
            $return=array('status'=>0,'msg'=>"亲，抽奖次数已用完<br/>再签到".$day."天，就可以获得抽奖机会哦~");
        }
        $this->ajaxReturn($return);
    }

}